import request from '@/config/axios'

const baseURL = '/official-website/unit/feed'

export type FeedDetail = {
  id?: string
  feedContent: string //内容
  feedTitle: string //标题
  feedShowType: number //1.对齐 ，2.不对齐
  feedType: number // 1.图文  2.视频
  imageUrls: string[] //图片地址
  videoUrl: string //视频地址
  videoCoverUrl: string //视频封面
  sortNo: number
}

export interface GetFeed extends PageParam {
  feedShowType?: number
  feedType?: number
}

// 创建信息流
export const createFeed = (data: FeedDetail) =>
  request.post<boolean>({
    url: `${baseURL}/create`,
    data
  })

// 根据信息流id获取信息流详情
export const getFeedById = (id: string) =>
  request.get<FeedDetail>({
    url: `${baseURL}/get-feed-by-id`,
    params: { id }
  })

// 修改信息流
export const updateFeed = (data: FeedDetail) =>
  request.post<boolean>({
    url: `${baseURL}/update`,
    data
  })
// 删除信息流
export const deleteFeed = async (id: string) => {
  return await request.delete<boolean>({
    url: `${baseURL}/delete?id=` + id
  })
}

// 分页查询信息流
export const getPageFeed = async (data: GetFeed) => {
  return await request.post<PageResult<FeedDetail>>({
    url: `${baseURL}/page`,
    data
  })
}
